package com.nbsaas.boot.app.data.entity;

import com.nbsaas.boot.app.api.domain.enums.RoleType;
import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.LongEntity;
import com.nbsaas.boot.rest.filter.Operator;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.util.Date;


@SearchBean(items = {
        @SearchItem(label = "应用", name = "appKey", key = "app.appKey", operator = Operator.eq)
})
@ComposeView
@FormAnnotation(model = "角色")
@Data
@Entity
@Comment("应用角色")
@Table(name = "sys_app_role")
public class AppRole extends LongEntity {


    @JoinColumn(name = "app_id")
    @Comment("应用")
    @SearchItem(label = "应用", name = "app", key = "app.id", operator = Operator.eq, classType = Long.class)
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private App app;


    /**
     * name 角色名称
     */
    @SearchItem(label = "角色名称", name = "name")
    @Comment("角色名称")
    private String name;


    /**
     * description 角色描述
     */
    @Comment("角色描述")
    private String remark;

    @SearchItem(label = "租户id", name = "tenantId", classType = Long.class, operator = Operator.eq)
    @Comment("租户id")
    private Long tenantId;

    @Comment("查看数据有效天数，不配置，-1的时候不限制范围")
    private Integer dataViewPeriod;

    @Comment("单据有效天数，不配置，-1的时候不限制范围")
    private Integer billViewPeriod;

    @Comment("报表有效天数，不配置，-1的时候不限制范围")
    private Integer reportViewPeriod;

    @SearchItem(label = "角色", name = "roleType", classType = RoleType.class, operator = Operator.eq)
    private RoleType roleType;


    @FormField(title = "添加时间", grid = true, width = "10000", ignore = true)
    @Comment("添加时间")
    private Date addDate;

    /**
     * 最新修改时间
     */
    @Comment("最新修改时间")
    private Date lastDate;
}
